﻿//-----------------------------------------------------------------------
// <copyright file="IoCConfigurationSection.cs" company="WpfDevelopment.com">
//     Copyright WpfDevelopment.com. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace WpfDevelopment.MVVM
{
    using System;
    using System.Configuration;
    using System.Globalization;
    using System.Reflection;
    using System.Resources;

    /// <summary>
    /// The IoC Configuration section used to set the IoC container to use
    /// </summary>
    public class IoCConfigurationSection : ConfigurationSection
    {
        /// <summary>
        /// The string manager that manages string resources
        /// </summary>
        private ResourceManager stringManager;

        /// <summary>
        /// Initializes a new instance of the <see cref="IoCConfigurationSection"/> class.
        /// </summary>
        public IoCConfigurationSection()
        {
            this.stringManager = new ResourceManager("WpfDevelopment.MVVM.DI.IoC", Assembly.GetAssembly(typeof(IoC)));
        }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        /// <value>The type of IoC container to create.</value>
        [ConfigurationProperty("type", DefaultValue = "", IsRequired = true)]
        public string TypeOfContainer
        {
            get
            {
                return base["type"] as string;
            }

            set
            {
                Throw<NullReferenceException>.When(
                    string.IsNullOrEmpty(value),
                    this.stringManager.GetString("typeStringIsNullOrEmpty", CultureInfo.CurrentUICulture),
                    typeof(IoC).FullName);

                base["type"] = value;
            }
        }
    }
}
